package com.atguigu.chapter5.transfrom;

import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;

/**
 * @ClassName: FlatMapDemo
 * @Description:
 * @Author: kele
 * @Date: 2021/4/5 15:47
 **/
public class FlatMapDemo {

    public static void main(String[] args) throws Exception {

        Configuration conf = new Configuration();
        conf.setInteger("rest.port",20000);

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env.setParallelism(2);

        DataStreamSource<Integer> ds = env.fromElements(1, 2, 3, 4, 5, 6, 7, 8, 9);

        //flatmap是一進多出的效果
        ds.flatMap(new FlatMapFunction<Integer, Integer>() {

            @Override
            public void flatMap(Integer integer, Collector<Integer> collector) throws Exception {
                collector.collect(integer);
                collector.collect(integer * integer);
            }
        }).print();


        env.execute();

    }
}
